<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;
class  Users extends  Controller{

    public  function  users(){


        $res = Request::instance();
        $url = $res->root(true);
        return view('users',compact('url'));


    }

    public  function  Ajax(){
        $res = Request::instance();
        if($res->isPost()){


           $mobile =  input("post.m");
           $password = md5(input("post.p"));
            $url = $res->root(true);
            $arr = [
                'user'=>$mobile,
                'password'=>$password
            ];
            $name = Db::name('user')->where(['user'=>$mobile])->select();

            if(!empty($name)){
                $user = Db::name('user')->where($arr)->select();
                if(!empty($user)){
                      session::set('username',$user[0]['user']);
                    return json(['msg'=>'登录成功','error'=>'0','url'=>"{$url}/admin/Manage/manage"]);
                }else{
                    return json(['msg'=>'账号和密码不匹配,请重新输入，或者联系管理员','error'=>1]);
                }
            }else{
                return json(['msg'=>'账号不存在,请联系管理员','error'=>2]);
            }
        }
    }

    public function Userlogin(){
        $request = Request::instance();
        $url = $request->root(true);
        Session::clear();
        $this->success("安全退出","users");
    }


    public  function  adminlogin(){

        Session::clear();
        $this->success('退出成功','users');


    }
}